﻿using System.Configuration;

namespace Hippo.Agent
{
    using System;
    using System.Threading;
    using Autofac;
    using Hippo.Common;
    using Hippo.Agent.Lib;

    public class Program
    {
        static Program()
        {
            /* Setup ContainerFactory */
            ContainerFactory.Load<AgentContainerBuilder>();
        }

        public static void Main(string[] args)
        {
            Console.Out.WriteLine("Hippo.Agent version " + HippoAssembly.Version);
            Console.Out.WriteLine(HippoAssembly.AssemblyCopyright);
            Console.Out.WriteLine("All Rights Reserved.\n");

            var configuration = new AgentConfigurationProfile(ConfigurationManager.AppSettings);
            var parser = new AgentCommandLineParser(configuration, new RegexFactory());

            parser.Parse(args);
            if (parser.UnrecognizedArguments.Count != 0)
            {
                parser.GetHelp("> Unrecognized command line option\n\n{0}", ExitCode.Error);
            }

            Console.WriteLine(@"Start listen for console");
            Console.WriteLine(@"End this process with CTRL+C");

            ContainerFactory.Current.Resolve<ConsoleClient>()
                .RegisterClient();
            
            // Listen for the connection to die and then try to reconnect
            Console.WriteLine("End this process with CTRL+C");
            Thread.Sleep(int.MaxValue);
        }
    }
}
